package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.Dispatchbean;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;


import java.util.ArrayList;
import java.util.List;

/**
 * 分派工程施工适配器
 * Created by tony on 2018/1/31.
 */

public class DispatchPatrolOrderAdapter extends BaseAdapter {

    private Context context;
    private List<MediaBean> datas = new ArrayList<MediaBean>();
    private LayoutInflater inflater;
    private ItemClickListener clickListener;
    private String tag = "";
    private int selectedPosition = -1;


    public DispatchPatrolOrderAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;
    }

    public void setData(List<MediaBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }

    }

    public void setItemClick(ItemClickListener clickListener) {
        this.clickListener = clickListener;
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public MediaBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_dispatch_patrol_order_lv, null);
            holder.tv_dokingcompany = convertView.findViewById(R.id.tv_dokingcompany);
            holder.tv_docking = convertView.findViewById(R.id.tv_docking);
            holder.tv_type = convertView.findViewById(R.id.tv_type);
            holder.tv_status = convertView.findViewById(R.id.tv_status);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        MediaBean mediaBean = datas.get(position);
        holder.tv_type.setText("内派");

        holder.tv_docking.setText("/" + mediaBean.getAssignReceiveAccountName());
        
        CommonEnum.AssignStatus assignStatus = mediaBean.getAssignStatus();
        if (null != assignStatus) {
            if (assignStatus == CommonEnum.AssignStatus.CREATED) {
                holder.tv_status.setText("");
            } else if (assignStatus == CommonEnum.AssignStatus.EDITED) {
                holder.tv_status.setText("");
            } else if (assignStatus == CommonEnum.AssignStatus.SEND) {
                holder.tv_status.setText("[等待接收]");
                holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_FCD505));
            } else if (assignStatus == CommonEnum.AssignStatus.RECEIVED) {
                holder.tv_status.setText("[已经接收]");
                holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_74BF73));
            } else if (assignStatus == CommonEnum.AssignStatus.RETURNED) {
                holder.tv_status.setText("[退回]");
                holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_c64149));
            } else if (assignStatus == CommonEnum.AssignStatus.COMPLETED) {
                holder.tv_status.setText("[完结]");
                holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_74BF73));
            }

        }

//
//        Dispatchbean dispatchbean = datas.get(position);
//        holder.tv_type.setText(dispatchbean.getDispatchType());
//        if (!TextUtils.isEmpty(dispatchbean.getDispatchCompany()))
//            holder.tv_dokingcompany.setText("/" + dispatchbean.getDispatchCompany());
//        holder.tv_docking.setText("/" + dispatchbean.getDispatchUserName());
//        CommonEnum.AssignStatus assignStatus = dispatchbean.getAssignStatus();
//        if (null != assignStatus) {
//            if (assignStatus.equals("CREATED")) {
//                holder.tv_status.setText("/" + "创建/未编辑");
//            } else if (assignStatus.equals("EDITED")) {
//                holder.tv_status.setText("/" + "创建/未编辑");
//            } else if (assignStatus.equals("SEND")) {
//                holder.tv_status.setText("/" + "创建/未编辑");
//            } else if (assignStatus.equals("/" + "创建/未编辑")) {
//                holder.tv_status.setText("/" + "创建/未编辑");
//            } else if (assignStatus.equals("RETURNED")) {
//                holder.tv_status.setText("/" + "创建/未编辑");
//            } else if (assignStatus.equals("COMPLETED")) {
//                holder.tv_status.setText("/" + "创建/未编辑");
//            }
//        }


        return convertView;
    }

    private class ViewHolder {
        private TextView tv_type;
        private TextView tv_dokingcompany;
        private TextView tv_docking;
        private TextView tv_status;

    }

}
